﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.BlackApart.Business.Reservations;
using blackhouse.Payments;

namespace blackhouse.Aparts.Web {
    public class PaymentTransactionExtension : IPaymentTransactionExtension {

        public void NotifyUpdate(IPaymentTransaction prevTransaction, IPaymentTransaction currentTransaction) {
            if (prevTransaction.Status != currentTransaction.Status) {
                if (currentTransaction.Status == PaymentTransactionStatus.CompleteTransaction) {
                    int reservationId = currentTransaction.OrderId;
                    IWebReservation reservation = blackhouse.BlackApart.Business.Factory.Instance().GetWebReservation(reservationId);
                    if (reservation.Status.Key == "waiting_payu")
                        reservation.ChangeStatus("payed");
                    else
                        throw new InvalidOperationException("Rezerwacja nie jest w stanie oczekiwania na płatność ONLINE");
                }
            }
        }

    }
}